<style>
.data-div {
	margin-top: 20px;
}
</style>
<template>
  	<div class="question">
    	<div class="content-div">
			<Row style="margin-top:10px">
				<Col span="14" class="table-form-input-select-col">
					<span class="alltitle" style="line-height:30px"><router-link to="项目列表"> 项目列表</router-link> > <router-link to="questionnaire"> 外部雇主调研板块</router-link></span>
				</Col>				
			</Row>
		</div>
		<div class="content-div">
			<Row style="margin-top:10px">
				<Col span="2">
					<router-link :to="{ name: 'questionmgr', params: { qid: qid }}"><Button>问题管理</Button></router-link>
				</Col>
				<Col span="2">
					<router-link :to="{ name: 'datamgr', params: { qid: qid }}"><Button type="primary">数据管理</Button></router-link>
				</Col>
				<Col span="2">
					<router-link :to="{ name: 'stylemgr', params: { qid: qid }}"><Button>样式管理</Button></router-link>
				</Col>				
				<Col span="2" offset="16">
					<Button type="info" @click="exportData">数据导出</Button>
				</Col>
			</Row>
		</div>
		<div class="content-div data-div">
			<Table :columns="columns" :data="data" border stripe ref="table"></Table>
		</div>
  	</div>
</template>
<script>
export default {
    data() {
		return {
			qid: 0,
			columns: [],
			data: [],
            list: []
		}
	},
	created(){
          //获取传入的参数
          var params = this.$route.params;
          this.qid = params.qid;

          var self = this
            $.ajax({
                url: "https://evp.51job.com/51job/api/51miniadmin/back.php?action=questionnaire_listlist&id=" + this.qid,
                type: "POST",
                dataType: "json",
                success: function(data) {

                    console.log(data);

                    if (data.data != null) {

                        var list = data.data
                        var columns = []

                        columns.push({title: '序列号', key: 'index', width: 100})
                        columns.push({title: '提交时间', key: 'time', width: 200})

                        for(var i = 0; i < list.length; i++) {
                        	columns.push({title: list[i].title, key: list[i].id, width: 150})
                        }

                        self.columns = columns

                        self.getDataList()
                    }

                }
            });
     },
    methods: {
    	getDataList() {
    		var self = this
            $.ajax({
                url: "https://evp.51job.com/51job/api/51miniadmin/back.php?action=questionnaire_userlist&id=" + this.qid,
                type: "POST",
                dataType: "json",
                success: function(data) {
                    if (data.data != null) {
                    	var list = data.data
                    	var array = [];
                        for(var i = 0; i < list.length; i++) {
                            try {
                                if (list[i].selection_all.length > 0) {
                                    var obj = JSON.parse(list[i].selection_all.replace(/\\/g,"&quot;"))
                                    obj.index = i + 1
                                    obj.time = new Date(parseInt(list[i].create_at * 1000 )).toLocaleString()
                                    array.push(obj)
                                    self.list.push(list[i])
                                }
                            } catch (error) {
                                console.log(error, list[i])
                            }
                        	
                        }
                        self.data = array
                        self.list = list
                    }
                }
            });
    	},
    	exportData() {
            this.$refs.table.exportCsv({
                filename: "问答信息"
            });
        }
    }
};
</script>


